package com.maimao.model.info;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 优惠券
 *
 * @author MaoLin Wang
 * @date 2020/11/28 10:20 上午
 */
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@TableName("mm_coupon")
public class Coupon implements Serializable {

    private static final long serialVersionUID = 1132968748409809255L;


    @TableId(type = IdType.AUTO)
    private Long id;

    /**
     * 1 通用券 用户都可以领 2 新人领取(注册后系统赠送) 3 首单优惠 4 指定用户（vip等） 『目前只支持1和2』
     */
    @TableField("`who`")
    @NotNull(message = "请选择使用群体")
    private Integer who;

    /**
     * 1 用户自己领取 2 系统发放
     */
    @TableField("`how`")
    @NotNull(message = "请选择领取方式")
    private Integer how;

    /**
     * 范围：1. 单品优惠 2.指定商品 3.全店铺使用 4.专区 5. 全场    『1、2、3用于店铺优惠券，4和5用于系统优惠券』
     */
    @TableField("`where`")
    @NotNull(message = "请选择适用范围")
    private Integer where;

    /**
     * 1 满减 2 立减
     */
    @TableField("`what`")
    @NotNull(message = "请选择减免方式")
    private Integer what;

    /**
     * 1 普通(规定时间范围内可用) 2 限时(如领取后几日内可用)
     */
    @TableField("`use_type`")
    @NotNull(message = "请选择期限类型")
    private Integer useType;

    @TableField("`type`")
    @NotNull(message = "请选择优惠券类型")
    private Integer type;

    @TableField("`name`")
    @NotBlank(message = "请输入优惠券名称")
    private String name;

    @TableField("`desc`")
    private String desc;

    @TableField("`start_time`")
    @NotNull(message = "请输入开始时间")
    @JsonFormat(shape = JsonFormat.Shape.STRING,pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime startTime;

    @TableField("`end_time`")
    @NotNull(message = "请输入结束时间")
    @JsonFormat(shape = JsonFormat.Shape.STRING,pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime endTime;

    /**
     * 最低消费(进行满减)
     */
    @TableField("`min`")
    private BigDecimal min;

    /**
     * 优惠金额 what为1 需满max_price，what为0 ，直接减
     */
    @TableField("`discount_price`")
    @NotNull(message = "请输入优惠金额")
    private BigDecimal discountPrice;

    @TableField("`count`")
    @NotNull(message = "请输入优惠券数量")
    @Min(1)
    private Integer count;

    @TableField("`count`")
    private Integer used;

    @TableField("`take_count`")
    private Integer takeCount;

    /**
     * 针对限时优惠券规定领取后使用期限(天)
     */
    @TableField("`limit`")
    private Integer limit;

    /**
     * json列表 where单品优惠和指定商品的目标商品id列表
     */
    @TableField("`goods_id`")
    private String goodsId;

    /**
     * where为3(专区时)优惠券的适用专区id 暂未实现
     */
    @TableField("`channel_id`")
    private Integer channelId;

    @TableField("`create_time`")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private LocalDateTime createTime;

    @TableField("`deleted`")
    private Integer deleted;

    @TableField("`shop_id`")
    private Long shopId;

    @Override
    public String toString() {
        return "Coupon{" +
                "id=" + id +
                ", who=" + who +
                ", how=" + how +
                ", where=" + where +
                ", what=" + what +
                ", useType=" + useType +
                ", type=" + type +
                ", name='" + name + '\'' +
                ", desc='" + desc + '\'' +
                ", startTime=" + startTime +
                ", endTime=" + endTime +
                ", min=" + min +
                ", discountPrice=" + discountPrice +
                ", count=" + count +
                ", used=" + used +
                ", takeCount=" + takeCount +
                ", limit=" + limit +
                ", goodsId='" + goodsId + '\'' +
                ", channel_id='" + channelId + '\'' +
                ", createTime=" + createTime +
                ", deleted=" + deleted +
                '}';
    }
}
